package com.example.example1;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.view.View;
import android.view.View.OnClickListener;
import android.app.AlertDialog;
import android.content.DialogInterface;
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final ArrayList<String> arrayWork = new ArrayList<String>();
        		
        		final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayWork);  
        	
        		final EditText workEnter = (EditText) findViewById(R.id.work_enter);
        		final EditText hourEdit = (EditText) findViewById(R.id.hour_edit);
        		final EditText minuteEdit = (EditText) findViewById(R.id.minnute_edit);
        	
        		final Button button = (Button) findViewById(R.id.button);
        		
        		final ListView list = (ListView) findViewById(R.id.list);

        		list.setAdapter(arrayAdapter);
        		
        		
        		OnClickListener add = new OnClickListener() {
        		@Override
        		public void onClick(View v) {
    
        		if (workEnter.getText().toString().equals("") ||hourEdit.getText().toString().equals("") ||minuteEdit.getText().toString().equals("")) { 
        		AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        		builder.setTitle("Info missing");
        		builder.setMessage("Please enter all information of the work"); 
        		builder.setPositiveButton("Continue", new 
        		DialogInterface.OnClickListener() {
        				public void 
        				onClick(DialogInterface dialog, int which) {
        				
        				} 
        				});
        				builder.show();
        				}
        			
        				else {
        				String str = 
        				workEnter.getText().toString() + " - " 
        				+ 
        				hourEdit.getText().toString() + ":"
        				+ 
        				minuteEdit.getText().toString();
        				arrayWork.add(0,str);
        				arrayAdapter.notifyDataSetChanged();
        				workEnter.setText("");
        				hourEdit.setText("");
        				minuteEdit.setText("");
        				}
        				}
        				};
        				//set Listener cho button
        				button.setOnClickListener(add); 
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
